package com.mall.common.util;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtils {
	public static int getRandomMinToMax(int min, int max) {
		Random random = new Random();
		return random.nextInt(max) % (max - min + 1) + min;
	}

	public static Long getLongRandomMinToMax(int min, int max) {
		Random random = new Random();
		int randomNo = random.nextInt(max) % (max - min + 1) + min;
		return Long.parseLong(randomNo + "");
	}

	/**
	 * 字符串中只保留数字
	 * @param str
	 * @return
	 */
	public static Integer getInterFromString(String str) {
		String numberStr = "";
		String regEx = "[^0-9]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		numberStr = m.replaceAll("").trim();
		return Integer.parseInt(numberStr);
	}

	public static void main(String[] args) {
		System.out.println(getInterFromString("asdfadsf2424gsgas34"));
	}
}
